package br.com.fafica.sisape.repositorioarray;

import java.util.ArrayList;

import br.com.fafica.sisape.model.Alergia;

public class RepositorioAlergia implements InterfaceRepositorioAlergia {
	
	static ArrayList <Alergia> alergias = new ArrayList<Alergia>();
	static Integer cod = 0;
	
	/* (non-Javadoc)
	 * @see br.com.fafica.sisape.repositorioarray.InterfaceRepositorioAlergia#createAlergia(br.com.fafica.sisape.model.Alergia, java.lang.Integer)
	 */
	@Override
	public void createAlergia(Alergia a, Integer codUsuario){
		cod++;
		a.setCod(cod);
		a.setCodUsuario(codUsuario);
		alergias.add(a);
	}
	/* (non-Javadoc)
	 * @see br.com.fafica.sisape.repositorioarray.InterfaceRepositorioAlergia#readAlergia(java.lang.Integer)
	 */
	@Override
	public ArrayList readAlergia(Integer cod){
		
		ArrayList<Alergia> listaAlergia = new ArrayList<>();
		Alergia a = new Alergia();
		for(int i=0; i < alergias.size(); i++){
			a = alergias.get(i);
			if(a.getCodUsuario() == cod){
				listaAlergia.add(a);
			}
		}
		return listaAlergia;
	}
	/* (non-Javadoc)
	 * @see br.com.fafica.sisape.repositorioarray.InterfaceRepositorioAlergia#updateAlergia(br.com.fafica.sisape.model.Alergia)
	 */
	@Override
	public void updateAlergia(Alergia a){
		System.out.println(a.getCod());
		System.out.println(a.getCodUsuario());
		for(int i = 0; i < alergias.size(); i++){
			if(alergias.get(i).getCod() == a.getCod()){
				alergias.set(i, a);
			}
		}
	}
	/* (non-Javadoc)
	 * @see br.com.fafica.sisape.repositorioarray.InterfaceRepositorioAlergia#deleteAlergia(br.com.fafica.sisape.model.Alergia)
	 */
	@Override
	public void deleteAlergia(Alergia a){
		
		for(int i = 0; i < alergias.size(); i++){
			if(alergias.get(i).getCod() == a.getCod()){
				alergias.remove(i);
			}
		}
	}

}
